<?php

namespace App\Ship\Parents\Transformers;

use Apiato\Core\Abstracts\Transformers\Transformer as AbstractTransformer;
use Carbon\Carbon;
use League\Fractal\Resource\Item;

abstract class Transformer extends AbstractTransformer
{
    public function nullableItem($data, $transformer, $resourceKey = null): ?Item
    {
        if (!empty($data)) return parent::item($data, $transformer, $resourceKey);
        else return null;
    }

    public function dateFormatter($dateTime): ?string
    {
        return $dateTime ? with(new Carbon($dateTime))->format($this->getDateFormat()) : null;
    }

    public function getDateFormat(): string
    {
        return 'd.m.Y';
    }

    public function dateTimeFormatter($dateTime): ?string
    {
        return $dateTime ? with(new Carbon($dateTime))->format($this->getDateTimeFormat()) : null;
    }

    public function getDateTimeFormat(): string
    {
        return 'd.m.Y H:m';
    }
}
